import numpy as np
import matplotlib.pyplot as plt

def func():
    # 示例数据
    x = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9])
    y = np.array([1.2, 1.9, 3.2, 4.0, 5.1, 6.2, 7.3, 8.0, 9.2])

    # 使用2次多项式拟合
    coeffs = np.polyfit(x, y, deg=2)
    poly = np.poly1d(coeffs)

    # 拟合结果
    x_fit = np.linspace(min(x), max(x), 100)
    y_fit = poly(x_fit)

    # 可视化
    plt.scatter(x, y, label="原始数据")
    plt.plot(x_fit, y_fit, color='red', label="拟合曲线")
    plt.legend()
    plt.show()

    x = 5.5
    print(f"{poly(x)}")

if __name__ == '__main__':
    func()